<template>
  <a-card :bordered="false">
    <v-table
      bordered
      ref="table"
      :data="loadData"
      :columns="columns"
    >
      <template v-slot:buttons>
        <a-button @click="$refs.socialForm.init('','add')" icon="plus" type="primary" v-action="'sys:social:save'">新建</a-button>
      </template>
      <span slot="action" slot-scope="{row,text}">
        <span v-action="'sys:social:update'">
          <a @click="edit(row)">修改</a>
          <a-divider type="vertical" />
        </span>
        <span v-action="'sys:social:del'">
          <a-popconfirm title="是否删除密钥" @confirm="del(row)" okText="是" cancelText="否">
            <a-icon slot="icon" type="question-circle-o" style="color: red" />
            <a href="javascript:;" style="color: red">删除</a>
            <a-divider type="vertical" />
          </a-popconfirm>
        </span>
        <span>
          <a @click="show(row)">查看</a>
        </span>
      </span>
    </v-table>
    <social-form
      ref="socialForm"
      @ok="queryPage"
    />
  </a-card>
</template>

<script>
import { fetchList, delObj } from '@/api/sys/social'
import { TableMixin } from '@/mixins/TableMixin'
import socialForm from './social-form'
export default {
  name: 'Client',
  mixins: [TableMixin],
  components: {
    socialForm
  },
  data () {
    return {
      columns: [
        {
          title: 'id',
          field: 'id'
        },
        {
          title: '类型',
          field: 'type'
        },
        {
          title: 'appId',
          width: '250px',
          field: 'appId'
        },
        {
          title: 'appSecret',
          width: '250px',
          field: 'appSecret'
        },
        {
          title: '回调地址',
          width: '250px',
          field: 'redirectUrl'
        },
        {
          title: '备注',
          field: 'remark'
        },
        {
          title: '操作',
          width: '200px',
          field: 'action',
          slot: true
        }
      ],
      queryParam: {
        type: ''
      },
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    edit (record) {
      this.$refs.socialForm.init(record.id, 'edit')
    },
    del (record) {
      delObj(record.id).then(res => {
        this.$message.info('删除成功')
        this.queryPage()
      })
    },
    show (record) {
      this.$refs.socialForm.init(record.id, 'show')
    }
  }
}
</script>

<style scoped>

</style>
